﻿using System.Net;
using System.Net.Sockets;
using Fvs_Service.Net;

namespace Fvs_Service
{
    public class RelayHandler:ISocketHandler
    {
        public SocketPack Unpack(Socket socket, IPEndPoint remoteEndPoint, List<byte> buffer, int offset)
        {
            if (buffer.Count == 8 && buffer[0] == 0x22)
            {
                int sum = 0;
                for (int i = 0; i < 7; ++i)
                {
                    sum += buffer[i];
                }
                if (buffer[7] == Convert.ToByte(sum))
                {
                    return new SocketPack
                    {
                            Result = AnalysisResult.Full,
                            Offset = 0,
                            Size = 8,
                            ProtocolId = buffer[2],
                            TimeStamp = 0
                    };
                }
            }
            return new SocketPack
            {
                Result = AnalysisResult.Empty,
                Offset = 0,
                Size = buffer.Count
            };
        }
    }
}
